home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / swingall.jar / javax / swing / text / rtf / RTFReader$AttributeTrackingDestination.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-07-15  |  7.6 KB  |  371 lines

  1. package javax.swing.text.rtf;
  2.  
  3. import java.awt.Color;
  4. import java.util.Dictionary;
  5. import java.util.Enumeration;
  6. import java.util.Hashtable;
  7. import javax.swing.text.AttributeSet;
  8. import javax.swing.text.MutableAttributeSet;
  9. import javax.swing.text.SimpleAttributeSet;
  10. import javax.swing.text.Style;
  11. import javax.swing.text.StyleConstants;
  12. import javax.swing.text.TabStop;
  13.  
  14. abstract class RTFReader$AttributeTrackingDestination implements RTFReader.Destination {
  15.    // $FF: synthetic field
  16.    private final RTFReader this$0;
  17.    MutableAttributeSet characterAttributes;
  18.    MutableAttributeSet paragraphAttributes;
  19.    MutableAttributeSet sectionAttributes;
  20.  
  21.    public RTFReader$AttributeTrackingDestination(RTFReader var1) {
  22.       this.this$0 = var1;
  23.       this.characterAttributes = this.rootCharacterAttributes();
  24.       var1.parserState.put("chr", this.characterAttributes);
  25.       this.paragraphAttributes = this.rootParagraphAttributes();
  26.       var1.parserState.put("pgf", this.paragraphAttributes);
  27.       this.sectionAttributes = this.rootSectionAttributes();
  28.       var1.parserState.put("sec", this.sectionAttributes);
  29.    }
  30.  
  31.    public void begingroup() {
  32.       MutableAttributeSet var1 = this.currentTextAttributes();
  33.       MutableAttributeSet var2 = this.currentParagraphAttributes();
  34.       AttributeSet var3 = this.currentSectionAttributes();
  35.       this.characterAttributes = new SimpleAttributeSet();
  36.       this.characterAttributes.addAttributes(var1);
  37.       this.this$0.parserState.put("chr", this.characterAttributes);
  38.       this.paragraphAttributes = new SimpleAttributeSet();
  39.       this.paragraphAttributes.addAttributes(var2);
  40.       this.this$0.parserState.put("pgf", this.paragraphAttributes);
  41.       this.sectionAttributes = new SimpleAttributeSet();
  42.       this.sectionAttributes.addAttributes(var3);
  43.       this.this$0.parserState.put("sec", this.sectionAttributes);
  44.    }
  45.  
  46.    public void close() {
  47.    }
  48.  
  49.    MutableAttributeSet currentParagraphAttributes() {
  50.       SimpleAttributeSet var1 = new SimpleAttributeSet(this.paragraphAttributes);
  51.       TabStop[] var3 = (TabStop[])this.this$0.parserState.get("_tabs_immutable");
  52.       if (var3 == null) {
  53.          Dictionary var4 = (Dictionary)this.this$0.parserState.get("_tabs");
  54.          if (var4 != null) {
  55.             int var5 = (Integer)var4.get("stop count");
  56.             var3 = new TabStop[var5];
  57.  
  58.             for(int var6 = 1; var6 <= var5; ++var6) {
  59.                var3[var6 - 1] = (TabStop)var4.get(new Integer(var6));
  60.             }
  61.  
  62.             this.this$0.parserState.put("_tabs_immutable", var3);
  63.          }
  64.       }
  65.  
  66.       if (var3 != null) {
  67.          var1.addAttribute("tabs", var3);
  68.       }
  69.  
  70.       Style var7 = (Style)this.this$0.parserState.get("paragraphStyle");
  71.       if (var7 != null) {
  72.          var1.setResolveParent(var7);
  73.       }
  74.  
  75.       return var1;
  76.    }
  77.  
  78.    public AttributeSet currentSectionAttributes() {
  79.       SimpleAttributeSet var1 = new SimpleAttributeSet(this.sectionAttributes);
  80.       Style var2 = (Style)this.this$0.parserState.get("sectionStyle");
  81.       if (var2 != null) {
  82.          var1.setResolveParent(var2);
  83.       }
  84.  
  85.       return var1;
  86.    }
  87.  
  88.    MutableAttributeSet currentTextAttributes() {
  89.       SimpleAttributeSet var1 = new SimpleAttributeSet(this.characterAttributes);
  90.       Integer var2 = (Integer)this.this$0.parserState.get("f");
  91.       String var4;
  92.       if (var2 != null) {
  93.          var4 = (String)this.this$0.fontTable.get(var2);
  94.       } else {
  95.          var4 = null;
  96.       }
  97.  
  98.       if (var4 != null) {
  99.          StyleConstants.setFontFamily(var1, var4);
  100.       } else {
  101.          var1.removeAttribute(StyleConstants.FontFamily);
  102.       }
  103.  
  104.       if (this.this$0.colorTable != null) {
  105.          Integer var3 = (Integer)this.this$0.parserState.get("cf");
  106.          if (var3 != null) {
  107.             Color var5 = this.this$0.colorTable[var3];
  108.             StyleConstants.setForeground(var1, var5);
  109.          } else {
  110.             var1.removeAttribute(StyleConstants.Foreground);
  111.          }
  112.       }
  113.  
  114.       if (this.this$0.colorTable != null) {
  115.          Integer var6 = (Integer)this.this$0.parserState.get("cb");
  116.          if (var6 != null) {
  117.             Color var7 = this.this$0.colorTable[var6];
  118.             var1.addAttribute(StyleConstants.Background, var7);
  119.          } else {
  120.             var1.removeAttribute(StyleConstants.Background);
  121.          }
  122.       }
  123.  
  124.       Style var8 = (Style)this.this$0.parserState.get("characterStyle");
  125.       if (var8 != null) {
  126.          var1.setResolveParent(var8);
  127.       }
  128.  
  129.       return var1;
  130.    }
  131.  
  132.    public void endgroup(Dictionary var1) {
  133.       this.characterAttributes = (MutableAttributeSet)this.this$0.parserState.get("chr");
  134.       this.paragraphAttributes = (MutableAttributeSet)this.this$0.parserState.get("pgf");
  135.       this.sectionAttributes = (MutableAttributeSet)this.this$0.parserState.get("sec");
  136.    }
  137.  
  138.    public void handleBinaryBlob(byte[] var1) {
  139.       this.this$0.warning("Unexpected binary data in RTF file.");
  140.    }
  141.  
  142.    public boolean handleKeyword(String var1) {
  143.       if (var1.equals("ulnone")) {
  144.          return this.handleKeyword("ul", 0);
  145.       } else {
  146.          Object var2 = RTFReader.access$0().get(var1);
  147.          if (var2 != null) {
  148.             RTFAttribute var3 = (RTFAttribute)var2;
  149.             boolean var4;
  150.             switch (var3.domain()) {
  151.                case 0:
  152.                   var4 = var3.set(this.characterAttributes);
  153.                   break;
  154.                case 1:
  155.                   var4 = var3.set(this.paragraphAttributes);
  156.                   break;
  157.                case 2:
  158.                   var4 = var3.set(this.sectionAttributes);
  159.                   break;
  160.                case 3:
  161.                   var4 = var3.set(this.this$0.documentAttributes);
  162.                   break;
  163.                case 4:
  164.                   RTFReader.access$1(this.this$0).backing = this.this$0.parserState;
  165.                   var4 = var3.set(RTFReader.access$1(this.this$0));
  166.                   RTFReader.access$1(this.this$0).backing = null;
  167.                   break;
  168.                default:
  169.                   var4 = false;
  170.             }
  171.  
  172.             if (var4) {
  173.                return true;
  174.             }
  175.          }
  176.  
  177.          if (var1.equals("plain")) {
  178.             this.resetCharacterAttributes();
  179.             return true;
  180.          } else if (var1.equals("pard")) {
  181.             this.resetParagraphAttributes();
  182.             return true;
  183.          } else if (var1.equals("sectd")) {
  184.             this.resetSectionAttributes();
  185.             return true;
  186.          } else {
  187.             return false;
  188.          }
  189.       }
  190.    }
  191.  
  192.    public boolean handleKeyword(String var1, int var2) {
  193.       boolean var3 = var2 != 0;
  194.       if (var1.equals("fc")) {
  195.          var1 = "cf";
  196.       }
  197.  
  198.       if (var1.equals("f")) {
  199.          this.this$0.parserState.put(var1, new Integer(var2));
  200.          return true;
  201.       } else if (var1.equals("cf")) {
  202.          this.this$0.parserState.put(var1, new Integer(var2));
  203.          return true;
  204.       } else {
  205.          Object var4 = RTFReader.access$0().get(var1);
  206.          if (var4 != null) {
  207.             RTFAttribute var5 = (RTFAttribute)var4;
  208.             boolean var6;
  209.             switch (var5.domain()) {
  210.                case 0:
  211.                   var6 = var5.set(this.characterAttributes, var2);
  212.                   break;
  213.                case 1:
  214.                   var6 = var5.set(this.paragraphAttributes, var2);
  215.                   break;
  216.                case 2:
  217.                   var6 = var5.set(this.sectionAttributes, var2);
  218.                   break;
  219.                case 3:
  220.                   var6 = var5.set(this.this$0.documentAttributes, var2);
  221.                   break;
  222.                case 4:
  223.                   RTFReader.access$1(this.this$0).backing = this.this$0.parserState;
  224.                   var6 = var5.set(RTFReader.access$1(this.this$0), var2);
  225.                   RTFReader.access$1(this.this$0).backing = null;
  226.                   break;
  227.                default:
  228.                   var6 = false;
  229.             }
  230.  
  231.             if (var6) {
  232.                return true;
  233.             }
  234.          }
  235.  
  236.          if (var1.equals("fs")) {
  237.             StyleConstants.setFontSize(this.characterAttributes, var2 / 2);
  238.             return true;
  239.          } else if (var1.equals("sl")) {
  240.             if (var2 == 1000) {
  241.                this.characterAttributes.removeAttribute(StyleConstants.LineSpacing);
  242.             } else {
  243.                StyleConstants.setLineSpacing(this.characterAttributes, (float)var2 / 20.0F);
  244.             }
  245.  
  246.             return true;
  247.          } else if (!var1.equals("tx") && !var1.equals("tb")) {
  248.             if (var1.equals("s") && this.this$0.paragraphStyles != null) {
  249.                this.this$0.parserState.put("paragraphStyle", this.this$0.paragraphStyles[var2]);
  250.                return true;
  251.             } else if (var1.equals("cs") && this.this$0.characterStyles != null) {
  252.                this.this$0.parserState.put("characterStyle", this.this$0.characterStyles[var2]);
  253.                return true;
  254.             } else if (var1.equals("ds") && this.this$0.sectionStyles != null) {
  255.                this.this$0.parserState.put("sectionStyle", this.this$0.sectionStyles[var2]);
  256.                return true;
  257.             } else {
  258.                return false;
  259.             }
  260.          } else {
  261.             float var12 = (float)var2 / 20.0F;
  262.             int var13 = 0;
  263.             Number var8 = (Number)this.this$0.parserState.get("tab_alignment");
  264.             if (var8 != null) {
  265.                var13 = var8.intValue();
  266.             }
  267.  
  268.             int var7 = 0;
  269.             var8 = (Number)this.this$0.parserState.get("tab_leader");
  270.             if (var8 != null) {
  271.                var7 = var8.intValue();
  272.             }
  273.  
  274.             if (var1.equals("tb")) {
  275.                var13 = 5;
  276.             }
  277.  
  278.             this.this$0.parserState.remove("tab_alignment");
  279.             this.this$0.parserState.remove("tab_leader");
  280.             TabStop var9 = new TabStop(var12, var13, var7);
  281.             Object var10 = (Dictionary)this.this$0.parserState.get("_tabs");
  282.             Integer var11;
  283.             if (var10 == null) {
  284.                var10 = new Hashtable();
  285.                this.this$0.parserState.put("_tabs", var10);
  286.                var11 = new Integer(1);
  287.             } else {
  288.                var11 = (Integer)((Dictionary)var10).get("stop count");
  289.                var11 = new Integer(1 + var11);
  290.             }
  291.  
  292.             ((Dictionary)var10).put(var11, var9);
  293.             ((Dictionary)var10).put("stop count", var11);
  294.             this.this$0.parserState.remove("_tabs_immutable");
  295.             return true;
  296.          }
  297.       }
  298.    }
  299.  
  300.    public abstract void handleText(String var1);
  301.  
  302.    protected void resetCharacterAttributes() {
  303.       this.handleKeyword("f", 0);
  304.       this.handleKeyword("cf", 0);
  305.       this.handleKeyword("fs", 24);
  306.       Enumeration var1 = RTFReader.access$0().elements();
  307.  
  308.       while(var1.hasMoreElements()) {
  309.          RTFAttribute var2 = (RTFAttribute)var1.nextElement();
  310.          if (var2.domain() == 0) {
  311.             var2.setDefault(this.characterAttributes);
  312.          }
  313.       }
  314.  
  315.       this.handleKeyword("sl", 1000);
  316.       this.this$0.parserState.remove("characterStyle");
  317.    }
  318.  
  319.    protected void resetParagraphAttributes() {
  320.       this.this$0.parserState.remove("_tabs");
  321.       this.this$0.parserState.remove("_tabs_immutable");
  322.       this.this$0.parserState.remove("paragraphStyle");
  323.       StyleConstants.setAlignment(this.paragraphAttributes, 0);
  324.       Enumeration var1 = RTFReader.access$0().elements();
  325.  
  326.       while(var1.hasMoreElements()) {
  327.          RTFAttribute var2 = (RTFAttribute)var1.nextElement();
  328.          if (var2.domain() == 1) {
  329.             var2.setDefault(this.characterAttributes);
  330.          }
  331.       }
  332.  
  333.    }
  334.  
  335.    protected void resetSectionAttributes() {
  336.       Enumeration var1 = RTFReader.access$0().elements();
  337.  
  338.       while(var1.hasMoreElements()) {
  339.          RTFAttribute var2 = (RTFAttribute)var1.nextElement();
  340.          if (var2.domain() == 2) {
  341.             var2.setDefault(this.characterAttributes);
  342.          }
  343.       }
  344.  
  345.       this.this$0.parserState.remove("sectionStyle");
  346.    }
  347.  
  348.    protected MutableAttributeSet rootCharacterAttributes() {
  349.       SimpleAttributeSet var1 = new SimpleAttributeSet();
  350.       StyleConstants.setItalic(var1, false);
  351.       StyleConstants.setBold(var1, false);
  352.       StyleConstants.setUnderline(var1, false);
  353.       StyleConstants.setForeground(var1, this.this$0.defaultColor());
  354.       return var1;
  355.    }
  356.  
  357.    protected MutableAttributeSet rootParagraphAttributes() {
  358.       SimpleAttributeSet var1 = new SimpleAttributeSet();
  359.       StyleConstants.setLeftIndent(var1, 0.0F);
  360.       StyleConstants.setRightIndent(var1, 0.0F);
  361.       StyleConstants.setFirstLineIndent(var1, 0.0F);
  362.       var1.setResolveParent(this.this$0.target.getStyle("default"));
  363.       return var1;
  364.    }
  365.  
  366.    protected MutableAttributeSet rootSectionAttributes() {
  367.       SimpleAttributeSet var1 = new SimpleAttributeSet();
  368.       return var1;
  369.    }
  370. }
  371.